package org.examcity.domain.fixtures;

import org.examcity.domain.User;
import org.examcity.domain.UserStatus;
import org.examcity.util.ReflectionUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * Entity builder for {@link User}.
 * @author Antonio Gomes
 */
@Component
@Scope("prototype")
public class UserBuilder extends EntityBuilder<User> {

	public UserBuilder username(String username) {
		entity.setUsername(username);
		return this;
	}

	public UserBuilder fullName(String fullName) {
		entity.setFullName(fullName);
		return this;
	}

	public UserBuilder email(String email) {
		entity.setEmail(email);
		return this;
	}

	public UserBuilder comments(String comments) {
		entity.setComments(comments);
		return this;
	}
	
	public UserBuilder superuser() {
		entity.setSuperuser(true);
		return this;
	}

	public UserBuilder inactive() {
		entity.deactivate();
		return this;
	}

	public UserBuilder active() {
		entity.activate();
		return this;
	}

	public UserBuilder deleted() {
		// Notice that we cannot invoke delete() on a transient entity because this is explicity
		// forbidden. So, we need a little trick here to bypass the check.
		ReflectionUtil.writeField(entity, "status", UserStatus.DELETED);	
		return this;
	}

}
